//
//  UserAddressEntity.m
//  SXH
//
//  Created by Jack on 15/9/15.
//  Copyright (c) 2015年 lyss. All rights reserved.
//

#import "UserAddressEntity.h"

@implementation UserAddressEntity
@synthesize addName,addPhone,baseAddress,detailAddress;
@synthesize isDefault;

- (instancetype)initWithAttributes:(NSDictionary *)attributes {
    
    self = [super init];
    if (!self) {
        return nil;
    }
    
    self.addName= [attributes valueForKeyPath:@"nickname"];
    self.addPhone = [attributes valueForKeyPath:@"phone"];
    self.baseAddress = [attributes valueForKeyPath:@"address_info"];
    self.detailAddress = [attributes valueForKeyPath:@"address_info"];
//    self.isDefault = ((NSNumber*)[attributes valueForKeyPath:@"isDefault"]).boolValue;
    
    self.ID = [attributes valueForKeyPath:@"id"];
    self.isDefault = [attributes valueForKeyPath:@"def"];
    self.pro_name = [attributes valueForKeyPath:@"pro_name"];
    self.city_name = [attributes valueForKeyPath:@"city_name"];
    self.district = [attributes valueForKeyPath:@"district"];
    
    return self;
}

/**
 *  将对象写入文件的时候调用
 *  怎样存储
 *
 *  @param aCoder aCoder
 */
- (void)encodeWithCoder:(NSCoder *)encoder{
    [encoder encodeObject:self.addName forKey:@"addName"];
    [encoder encodeObject:self.addPhone forKey:@"addPhone"];
    [encoder encodeObject:self.baseAddress forKey:@"baseAddress"];
    [encoder encodeObject:self.detailAddress forKey:@"detailAddress"];
    [encoder encodeObject:[NSNumber numberWithBool: self.isDefault] forKey:@"isDefault"];
}

- (id)initWithCoder:(NSCoder *)decoder{
    if(self = [super init]) {
        self.addName = [decoder decodeObjectForKey:@"addName"];
        self.addPhone = [decoder decodeObjectForKey:@"addPhone"];
        self.baseAddress = [decoder decodeObjectForKey:@"baseAddress"];
        self.detailAddress = [decoder decodeObjectForKey:@"detailAddress"];
//        self.isDefault = ((NSNumber*)[decoder decodeObjectForKey:@"isDefault"]).boolValue;
    }
    
    return self;
}

@end